from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-14 14:16:26.584180
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 14, Oct, 2022
Time: 14:16:35
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.7031
Nobs: 809.000 HQIC: -51.0250
Log likelihood: 10479.4 FPE: 5.66291e-23
AIC: -51.2255 Det(Omega_mle): 5.07015e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296604 0.052614 5.637 0.000
L1.Burgenland 0.108957 0.035390 3.079 0.002
L1.Kärnten -0.106450 0.018844 -5.649 0.000
L1.Niederösterreich 0.210293 0.074019 2.841 0.004
L1.Oberösterreich 0.099939 0.071004 1.408 0.159
L1.Salzburg 0.250715 0.037698 6.651 0.000
L1.Steiermark 0.038885 0.049361 0.788 0.431
L1.Tirol 0.106309 0.040026 2.656 0.008
L1.Vorarlberg -0.058960 0.034414 -1.713 0.087
L1.Wien 0.058243 0.063369 0.919 0.358
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063988 0.108907 0.588 0.557
L1.Burgenland -0.033689 0.073254 -0.460 0.646
L1.Kärnten 0.047784 0.039006 1.225 0.221
L1.Niederösterreich -0.172529 0.153214 -1.126 0.260
L1.Oberösterreich 0.385337 0.146974 2.622 0.009
L1.Salzburg 0.286681 0.078032 3.674 0.000
L1.Steiermark 0.106279 0.102175 1.040 0.298
L1.Tirol 0.313468 0.082851 3.784 0.000
L1.Vorarlberg 0.025285 0.071235 0.355 0.723
L1.Wien -0.015944 0.131169 -0.122 0.903
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189903 0.027014 7.030 0.000
L1.Burgenland 0.090097 0.018170 4.959 0.000
L1.Kärnten -0.008456 0.009675 -0.874 0.382
L1.Niederösterreich 0.264519 0.038004 6.960 0.000
L1.Oberösterreich 0.126473 0.036456 3.469 0.001
L1.Salzburg 0.047932 0.019355 2.476 0.013
L1.Steiermark 0.017059 0.025344 0.673 0.501
L1.Tirol 0.094438 0.020551 4.595 0.000
L1.Vorarlberg 0.059365 0.017669 3.360 0.001
L1.Wien 0.119707 0.032535 3.679 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110007 0.027676 3.975 0.000
L1.Burgenland 0.044250 0.018616 2.377 0.017
L1.Kärnten -0.016107 0.009912 -1.625 0.104
L1.Niederösterreich 0.192870 0.038935 4.954 0.000
L1.Oberösterreich 0.294179 0.037349 7.876 0.000
L1.Salzburg 0.115259 0.019830 5.812 0.000
L1.Steiermark 0.099759 0.025965 3.842 0.000
L1.Tirol 0.116319 0.021054 5.525 0.000
L1.Vorarlberg 0.070648 0.018102 3.903 0.000
L1.Wien -0.027572 0.033333 -0.827 0.408
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.127831 0.050230 2.545 0.011
L1.Burgenland -0.051607 0.033786 -1.527 0.127
L1.Kärnten -0.040506 0.017990 -2.252 0.024
L1.Niederösterreich 0.169906 0.070665 2.404 0.016
L1.Oberösterreich 0.137379 0.067787 2.027 0.043
L1.Salzburg 0.285071 0.035990 7.921 0.000
L1.Steiermark 0.034735 0.047125 0.737 0.461
L1.Tirol 0.164934 0.038212 4.316 0.000
L1.Vorarlberg 0.104087 0.032855 3.168 0.002
L1.Wien 0.070349 0.060497 1.163 0.245
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060546 0.039804 1.521 0.128
L1.Burgenland 0.038821 0.026774 1.450 0.147
L1.Kärnten 0.050733 0.014256 3.559 0.000
L1.Niederösterreich 0.225769 0.055998 4.032 0.000
L1.Oberösterreich 0.282471 0.053717 5.258 0.000
L1.Salzburg 0.051422 0.028520 1.803 0.071
L1.Steiermark -0.007654 0.037344 -0.205 0.838
L1.Tirol 0.149591 0.030281 4.940 0.000
L1.Vorarlberg 0.070820 0.026036 2.720 0.007
L1.Wien 0.078452 0.047941 1.636 0.102
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.178145 0.047570 3.745 0.000
L1.Burgenland -0.005968 0.031997 -0.187 0.852
L1.Kärnten -0.061216 0.017037 -3.593 0.000
L1.Niederösterreich -0.083982 0.066923 -1.255 0.210
L1.Oberösterreich 0.192364 0.064198 2.996 0.003
L1.Salzburg 0.057216 0.034084 1.679 0.093
L1.Steiermark 0.230638 0.044629 5.168 0.000
L1.Tirol 0.494273 0.036189 13.658 0.000
L1.Vorarlberg 0.049592 0.031115 1.594 0.111
L1.Wien -0.048820 0.057294 -0.852 0.394
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161958 0.054617 2.965 0.003
L1.Burgenland -0.011408 0.036737 -0.311 0.756
L1.Kärnten 0.065905 0.019561 3.369 0.001
L1.Niederösterreich 0.200300 0.076837 2.607 0.009
L1.Oberösterreich -0.061108 0.073708 -0.829 0.407
L1.Salzburg 0.216568 0.039133 5.534 0.000
L1.Steiermark 0.113623 0.051241 2.217 0.027
L1.Tirol 0.077260 0.041550 1.859 0.063
L1.Vorarlberg 0.124581 0.035725 3.487 0.000
L1.Wien 0.114355 0.065782 1.738 0.082
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.353818 0.031834 11.114 0.000
L1.Burgenland 0.005669 0.021413 0.265 0.791
L1.Kärnten -0.023610 0.011402 -2.071 0.038
L1.Niederösterreich 0.223759 0.044786 4.996 0.000
L1.Oberösterreich 0.175257 0.042962 4.079 0.000
L1.Salzburg 0.047544 0.022809 2.084 0.037
L1.Steiermark -0.016498 0.029866 -0.552 0.581
L1.Tirol 0.108976 0.024218 4.500 0.000
L1.Vorarlberg 0.073728 0.020822 3.541 0.000
L1.Wien 0.052594 0.038342 1.372 0.170
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041176 0.152708 0.189989 0.157380 0.124268 0.113786 0.065670 0.227054
Kärnten 0.041176 1.000000 -0.002615 0.129729 0.041484 0.095957 0.429474 -0.053121 0.101080
Niederösterreich 0.152708 -0.002615 1.000000 0.336887 0.154538 0.300274 0.111205 0.183905 0.328390
Oberösterreich 0.189989 0.129729 0.336887 1.000000 0.232151 0.332607 0.172653 0.172492 0.262654
Salzburg 0.157380 0.041484 0.154538 0.232151 1.000000 0.145627 0.127076 0.149060 0.134466
Steiermark 0.124268 0.095957 0.300274 0.332607 0.145627 1.000000 0.153314 0.140942 0.079040
Tirol 0.113786 0.429474 0.111205 0.172653 0.127076 0.153314 1.000000 0.115150 0.155248
Vorarlberg 0.065670 -0.053121 0.183905 0.172492 0.149060 0.140942 0.115150 1.000000 0.007398
Wien 0.227054 0.101080 0.328390 0.262654 0.134466 0.079040 0.155248 0.007398 1.000000